package com.zzgele.qmzb.api.utils;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zzgele.qmzb.api.core.Constants;

import java.util.HashMap;

/**
 * Created by Martin on 2017-07-11.
 */
public class PageUtil {

    public static void startPage(int page, int page_size) {
        startPage(page, page_size,"");
    }

    private static void startPage(int page, int page_size, String order) {
        page = page<=0 ? 1 :page;
        page_size = page_size<=0 ? Constants.PAGE_SIZE_DEF : page_size;
        PageHelper.startPage(page, page_size);
     
    }

    public static HashMap getPageInfoHashMap(PageInfo pageInfo){
        HashMap hasMap = new HashMap();
        hasMap.put("page", pageInfo.getPageNum());
        hasMap.put("pages", pageInfo.getPages());
        hasMap.put("hasNextPage", pageInfo.getPageNum() < pageInfo.getPages());
        hasMap.put("list", pageInfo.getList());
        return hasMap;
    }
}
